import pathToRegexp from 'path-to-regexp/index';
import {getMaillist,postMaillist,getBMZZ,deleteMaillist,putMaillist} from 'services/app';
export default {
    namespace: 'maillist',
    state: {
        pages:1,
        record:{},
    },
    subscriptions: {
        setupHistory ({ dispatch, history }) {
            history.listen((location) => {
                const match = pathToRegexp('/home').exec(location.pathname);
            });
        },
        setup ({ dispatch }) {},
    },
    effects: {
        //获取通讯录
        *getMaillist ({ payload }, { call, put }){
            const {data,total} = yield call(getMaillist, payload);
            yield put({ type: 'save', payload: {getMaillistData:data,total:total,pages:payload.pageNumber}});
        },
        //输入等于输入
        *inputOut ({ payload }, { put }){
            yield put({ type: 'save', payload: payload });
        },
        //添加通讯录
        *postMaillist ({ payload }, { call, put }){
            const data = yield call(postMaillist, payload);
            if(data.code == 0){
                yield put({ type: 'save', payload: {pages:0,visible:false} });
            }
        },
        //删除通讯录
        *deleteMaillist ({ payload }, { call, put }){
            const data = yield call(deleteMaillist, payload);
            if(data.code == 0){
                yield put({ type: 'save', payload: {pages:0} });
            }
        },
        //修改通讯录
        *putMaillist ({ payload }, { call, put }){
            const data = yield call(putMaillist, payload);
            if(data.code == 0){
                yield put({ type: 'save', payload: {pages:0,visible:false} });
            }
        },
        //获取部门职责
        *getBMZZ ({ payload }, { call, put }){
            const {data} = yield call(getBMZZ, payload);
            yield put({ type: 'save', payload: {getBMZZData:data,visible:true} });
        },
    },
    reducers: {
        save (state, { payload }) {
            return { ...state, ...payload };
        },
    },
};
